/**
 * @Author ZhangCuirong
 * @Date 2025/9/17 16:07
 * @description:
 */
public class Solution680 {
    public boolean validPalindrome(String s) {
        int left = 0, right = s.length() - 1;
        while (left < right) {
            if (s.charAt(left) == s.charAt(right)) {
                left++;
                right--;
            } else {
                return validPalindrome(s, left + 1, right) || validPalindrome(s, left, right - 1);
            }
        }
        return true;
    }

    public boolean validPalindrome(String s, int low, int high) {
        if (low > high) {
            return false;
        }
        int left = low, right = high;
        while (left < right) {
            if (s.charAt(left) == s.charAt(right)) {
                left++;
                right--;
            } else {
                return false;
            }
        }
        return true;
    }

    public static void main(String[] args) {
        Solution680 solution = new Solution680();
        System.out.println(solution.validPalindrome("aba"));
        System.out.println(solution.validPalindrome("abca"));
        System.out.println(solution.validPalindrome("abc"));
        System.out.println(solution.validPalindrome("eceec"));
    }
}
